package com.lee.mybatis.mapper;

import com.lee.mybatis.entity.Emp;
import com.lee.mybatis.entity.PurchaseOrder;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.Date;
import java.util.List;


/**
 * @author Lee
 */
public interface PurchaseOrderMapper {
    /**
     *添加进货订单记录
     * @param purchaseOrder 进货订单记录
     *
     */
    void insert(PurchaseOrder purchaseOrder);

    /**
     * 按主键查询一条进货订单记录及对应进货人信息
     * @param id 主键
     * @return 一条进货订单记录及对应进货人信息
     *
     */
    PurchaseOrder selectById(@Param("id") int id);

    /**
     *查询所有进货订单信息，同时查询对应进货人信息
     * @return 所有进货订单及其对应进货人信息
     *
     */
    List<PurchaseOrder> selectWithEmpByJoin();

    /**
     *查询所有进货订单信息，分步查询对应进货人信息
     * @return 所有进货订单及其对应进货人信息
     *
     */
    List<PurchaseOrder> selectWithEmpBySelect();

    /**
     *查询所有进货订单信息，同时查询对应进货人信息
     * @return 所有进货订单及其对应进货人信息
     *
     */
    @Select("select id, order_no, emp_id, creat_time, total_price, info from psi.purchase_order")
    @Results({
            @Result(column = "id", property = "id",id = true),
            @Result(column = "order_no", property = "orderNo", javaType = String.class, jdbcType = JdbcType.VARCHAR),
            @Result(column = "emp_id", property = "empId"),
            @Result(column = "creat_time", property = "createTime", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "total_price", property = "totalPrice", javaType = Double.class,jdbcType = JdbcType.DECIMAL),
            @Result(column = "info", property = "info",javaType = String.class,jdbcType = JdbcType.VARCHAR),
            @Result(property = "emp", javaType = Emp.class, column = "emp_id", jdbcType = JdbcType.INTEGER,
                    one = @One(select ="com.lee.mapper.EmpMapper.selectByEmp"))
    })
    List<PurchaseOrder> selectWithEmpByOne();

    /**
     * 修改一条进货订单信息
     * @param purchaseOrder 进货订单信息
     *
     */
    void updateById (PurchaseOrder purchaseOrder);

    /**
     * 按主键删除一条进货订单信息
     * @param id 主键
     *
     */
    void deleteById(@Param("id") int id);
}
